﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

using Tao;
using Tao.OpenGl;
using VoltGameEditor.Properties;
using WeifenLuo.WinFormsUI.Docking;

using VCMDL.NET;

namespace VoltGameEditor
{
    public partial class MainWin : Form
    {
        public GlControl glctrl = new GlControl();

        #region MainWin events

        public MainWin()
        {
            InitializeComponent();
        }

        private void MainWin_Load(object sender, EventArgs e)
        {

            Program.Console.rtb_output.Text = "[ Volt Game Editor ]----[ Version 0.0.8.0 ALPHA ]\n++Initializing...\n";

            m_vport_togGrid.Checked = true;
            m_vport_togLighting.Checked = false;
            Program.ObjPane.tabControl2.SelectedIndex = 0;
            
            Program.startPage.Show(dp_docs);
        }

        private void MainWin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
            {
                functions.StartHelp(this, 0);
            }
            else if (e.KeyCode == Keys.Oemtilde)
            {
                e.SuppressKeyPress = true;
                Program.Console.ShowConsole(0);
            }
            else if (e.KeyCode == AppSettings.MouseKeyboardSettings.BoundKeys[Globals.Bind.Grid_Up])
            {
                /*e.SuppressKeyPress = true;
                if (int.Parse(ribbon1.grid_size.Text) >= 1024)
                    return;
                ribbon1.grid_size.Text = (int.Parse(ribbon1.grid_size.Text) * 2).ToString();

                functions.ChangeGrid(int.Parse(ribbon1.grid_size.Text));*/
            }
            else if (e.KeyCode == AppSettings.MouseKeyboardSettings.BoundKeys[Globals.Bind.Grid_Down])
            {
                /*e.SuppressKeyPress = true;
                if (int.Parse(ribbon1.grid_size.Text) <= 1)
                    return;
                ribbon1.grid_size.Text = (int.Parse(ribbon1.grid_size.Text) / 2).ToString();

                functions.ChangeGrid(int.Parse(ribbon1.grid_size.Text));*/
            }
        }

        private void MainWin_FormClosing(object sender, FormClosingEventArgs e)
        {
            AppSettings.WriteMainINI();
            AppSettings.WriteThemesINI();
            AppSettings.WriteGameINI();
        }

        #endregion

        #region Menu Events
        /// <summary>
        /// All menu related events go here...
        /// </summary>
        private void m_config_Click(object sender, EventArgs e)
        {
            Program.Settings.plpi = 3;
            Program.Settings.ShowDialog();
        }

        private void m_Hcontents_Click(object sender, EventArgs e)
        {
            functions.StartHelp(this, 0);
        }
        private void m_faq_Click(object sender, EventArgs e)
        {
            functions.StartHelp(this, 1);
        }
        private void m_website_Click(object sender, EventArgs e)
        {
            Process.Start("http://www.voltGE.glennfamily.us/");
        }
        private void m_about_Click(object sender, EventArgs e)
        {
            //Program.About.ShowDialog();
        }

        /*private void m_showStart_Click(object sender, EventArgs e)
        {
            if (Globals.currDocSaved == false & Globals.docOpen == true)
            {
                DialogResult = MessageBox.Show("The current document is not saved.\nDo you want to save before closing it?", "Exclamation", MessageBoxButtons.YesNoCancel);
                switch (DialogResult)
                {
                    case System.Windows.Forms.DialogResult.Yes:
                        {
                            break;
                        }
                    case System.Windows.Forms.DialogResult.No:
                        {
                            break;
                        }
                    case System.Windows.Forms.DialogResult.Cancel:
                        {
                            break;
                        }
                }
            }
            foreach (Form mdiC in Program.mainWin.MdiChildren)
            {
                mdiC.Hide();
            }
            Program.startPage.Show(dp_docs);
        }*/

        private void m_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void m_persp_3d_Click(object sender, EventArgs e)
        {
            glctrl.Perspective = Viewport.Perspectives.ThreeDScene;
        }
        private void m_persp_top_Click(object sender, EventArgs e)
        {
            glctrl.Perspective = Viewport.Perspectives.Top;
        }
        private void m_persp_side_Click(object sender, EventArgs e)
        {
            glctrl.Perspective = Viewport.Perspectives.Side;
        }
        private void m_persp_front_Click(object sender, EventArgs e)
        {
            glctrl.Perspective = Viewport.Perspectives.Front;
        }

        /*private void m_matBrowser_Click(object sender, EventArgs e)
        {
            if (Program.MatBrowser.Visible)
            {
                Program.MatBrowser.BringToFront();
                return;
            }

            Program.MatBrowser.Show(dp_docs);
        }*/

        private void m_togLighting_Click(object sender, EventArgs e)
        {
            if (m_vport_togLighting.Checked == true)
                glctrl.renderLighting = true;
            else
                glctrl.renderLighting = false;
            glctrl.Draw();
        }

        private void m_togGrid_Click(object sender, EventArgs e)
        {
            if (m_vport_togGrid.Checked == true)
                glctrl.showGrid = true;
            else
                glctrl.showGrid = false;
            glctrl.Draw();
        }

        private void m_shadWireframe_Click(object sender, EventArgs e)
        {
            glctrl.MakeCurrent();
            glctrl.ShadeMode = Shading.Wireframe;
        }

        private void m_shadSolid_Click(object sender, EventArgs e)
        {
            glctrl.MakeCurrent();
            glctrl.ShadeMode = Shading.Solid;
        }

        private void m_shadTexture_Click(object sender, EventArgs e)
        {
            glctrl.MakeCurrent();
            glctrl.ShadeMode = Shading.Textured;
        }

        private void m_prefabFactory_Click(object sender, EventArgs e)
        {
            Program.Prefabs.Show(dp_docs);
        }
        private void m_objectBrowser_Click(object sender, EventArgs e)
        {
            Program.ObjPane.Show(dp_docs);
        }

        private void m_objectFactory_Click(object sender, EventArgs e)
        {
            //Program.CustObj.Show(dp_docs);
        }

        private void m_import_Click(object sender, EventArgs e)
        {

        }

        private void m_gameCfg_Click(object sender, EventArgs e)
        {
            Program.Settings.plpi = 5;
            Program.Settings.Show(dp_docs);
        }

        private void m_startPage_Click(object sender, EventArgs e)
        {
            Program.startPage.Show(dp_docs);
        }

        private void m_settings_Click(object sender, EventArgs e)
        {
            Program.Settings.Show(dp_docs);
            Program.Settings.Size = new Size(662, 363);
        }

        #endregion //<<-----END MENUS--------------------------------->>

        private void b_2dLock_Click(object sender, EventArgs e)
        {
            if (b_2dLock.Text.Contains("Lock"))
            {
                b_2dLock.Image = VoltGameEditor.Properties.Resources.blueJelly_Lock;
                b_2dLock.Text = "Unlock 2d Viewports";
                //rest of the code here
                //locks the 2d view so zooming and panning are linked
            }
            else if (b_2dLock.Text.Contains("Unlock"))
            {
                b_2dLock.Image = VoltGameEditor.Properties.Resources.blueJelly_Unlock;
                b_2dLock.Text = "Lock 2d Viewports";
                //rest of the code here
                //unlocks the 2d view so zooming and panning are not linked
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            cm_mainMenu.Show(pictureBox1, new Point(pictureBox1.Location.X, pictureBox1.Location.Y + pictureBox1.Height));
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = Properties.Resources.volt_hov3;
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = Properties.Resources.volt;
        }


    }
}
